<?php

/**
 * 赞的功能  
 * @author top
 *
 */
class wlike extends CWidget {
	
	public $model = false;
	
	private $_like = false;
	
	/**
	 * (non-PHPdoc)
	 *
	 * @see CWidget::init()
	 */
	public function init() {
		$user = Yii::app ()->user;
		$user_id = $user->id;
		
		// 可以赞
		if (Educators::model ()->canLike ( $this->model->id )) {
			$this->_like = true;
		} else {
			// 取消赞
			$this->_like = false;
		}
	}
	
	/**
	 * (non-PHPdoc)
	 *
	 * @see CWidget::run()
	 */
	public function run() {
		
		// 可以赞
		if ($this->_like) {
			$url = Educators::model ()->getLikeUrl ( $this->model->profile->nick );
			echo CHtml::ajaxLink ( '赞', $url, array ('success'=>'function(Txt){var json = eval(\'Txt\'); if(json.code==200){}}'), array ('class' => 'btn' ) );
		} else {
			// 取消赞
			$url = Educators::model ()->getDislikeUrl ( $this->model->profile->nick );
			echo CHtml::ajaxLink ( '取消赞', $url, array (), array ('class' => 'btn' ) );
		}
		
	}

}